using System.IO;

namespace Pro.Data
{
    enum DataBaseType
    {
        SQLite, MySQL, SQLSever
    }
    class SQLHelper
    {
        public string DBPath { get; set; }
        public string SqliteConnectString { get; set; }
        public string MySQLConnectString { get; set; }
        public string SQLSeverConnectString { get; set; }
        public SqliteSever Sqlite=new SqliteSever();
        public MySqlSever MySQL=new MySqlSever();
        public SqlSever SQLSever=new SqlSever();
        void CreatDB()
        {
            if (string .IsNullOrEmpty(DBPath))
            {
                return;
            }
            if (File.Exists(DBPath)) return;
            FileStream file = new FileStream(DBPath, FileMode.Create);
            file.Flush();
            file.Close();
        }
        public void InitDB(DataBaseType dataBaseType)
        {
            CreatDB();
            switch (dataBaseType)
            {
                case DataBaseType.SQLite:
                    Sqlite.ConnectDB();
                    foreach (var item in MYReFlection.GetInterFaceChildInAssembly(typeof(BaseTableMode)))
                    {
                        if (!Sqlite.ExistTable(item))
                        {
                            Sqlite.CreatTable(item);
                        }
                    }
                    Sqlite.CloseDB();
                    break;
                case DataBaseType.MySQL:
                    MySQL.ConnectDB();
                    foreach (var item in MYReFlection.GetInterFaceChildInAssembly(typeof(BaseTableMode)))
                    {
                        if (!MySQL.ExistTable(item))
                        {
                            MySQL.CreatTable(item);
                        }
                    }
                    MySQL.CloseDB();
                    break;
                case DataBaseType.SQLSever:
                    SQLSever.ConnectDB();
                    foreach (var item in MYReFlection.GetInterFaceChildInAssembly(typeof(BaseTableMode)))
                    {
                        if (!SQLSever.ExistTable(item))
                        {
                            SQLSever.CreatTable(item);
                        }
                    }
                    SQLSever.CloseDB();
                    break;
                default:
                    break;
            }


        }
    }
}
